package com.kd.juhaowan.ui.holder;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.kd.juhaowan.R;
import com.kd.juhaowan.http.model.GameModel;
import com.kd.juhaowan.utils.GlideHelper;
import com.kd.juhaowan.utils.LogUtil;


import net.lucode.hackware.magicindicator.buildins.UIUtil;


public class BannerPagerViewHolder extends RecyclerView.ViewHolder {

    ImageView imageView;
    TextView nameView;
    TextView starView;
    TextView catView;
    TextView peopleView;
    LinearLayout zhekouLayout;
    TextView zhekouText;
    LinearLayout tagListview;
    private Context context;
    private LinearLayout.LayoutParams params;
//    ImageView textImage;

    public BannerPagerViewHolder(@NonNull View itemView, Context context) {
        super(itemView);
        this.context = context;
        this.imageView = itemView.findViewById(R.id.item_image);
//        textImage = itemView.findViewById(R.id.item_textbg);
        nameView = itemView.findViewById(R.id.item_name);
        starView = itemView.findViewById(R.id.item_star);
        catView = itemView.findViewById(R.id.item_cat);
        peopleView = itemView.findViewById(R.id.item_people);
        zhekouLayout = itemView.findViewById(R.id.item_zhekou_layout);
        zhekouText = itemView.findViewById(R.id.item_zhekou_text);
        tagListview = itemView.findViewById(R.id.gamelist_tag);
        params =new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.rightMargin= UIUtil.dip2px(context,5);
    }

    public void loadGoodsImage(GameModel model){
//        imageView.setImageResource(R.mipmap.icon_banner_defalut);
        GlideHelper.loadGoodsCover(Glide.with(itemView), imageView,model.getIndex_coverimage());

//        Resources res = context.getResources();
//        Bitmap scaledBitmap = BitmapFactory.decodeResource(res, R.mipmap.ic_launcher);
//
//        //        scaledBitmap为目标图像，10是缩放的倍数（越大模糊效果越高）
//        Bitmap blurBitmap = FastBlurUtil.toBlur(scaledBitmap, 100);
//        textImage.setScaleType(ImageView.ScaleType.FIT_XY);
//        textImage.setImageBitmap(blurBitmap);


        nameView.setText(model.getName());
        starView.setText(model.getScore());
        catView.setText(model.getCat_name());
        peopleView.setText(model.getPeople_are_playing()+"人在玩");

        if(model.getDiscount()>0){
            zhekouLayout.setVisibility(View.VISIBLE);
            zhekouText.setText(model.getDiscount()+"折直充");
        }else{
            zhekouLayout.setVisibility(View.GONE);
        }

        String[] tags =model.getTags();
        LogUtil.debugLog("dafa"+tags==null?"null":tags.length+"");
        if(tags!=null&&tags.length>0){
            tagListview.setVisibility(View.VISIBLE);
            tagListview.removeAllViews();
            for (String adb:tags) {
                TextView tv=new TextView(context);
                tv.setGravity(Gravity.CENTER);
                tv.setBackgroundResource(R.drawable.tag_bg);
                tv.setPadding(UIUtil.dip2px(context,5),0,UIUtil.dip2px(context,5),0);
                tv.setText(adb);
                tv.setTextColor(context.getColor(R.color.login_edit_hint));
                tv.setTextSize(11);
                tagListview.addView(tv,params);
            }


//            searchHistoryAdapter.resetAdapterData(Arrays.asList(tags));
        }else {
            tagListview.setVisibility(View.GONE);
        }

    }
}
